// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace QuoteAdvantageEditor
{
	/// <summary>
	/// Summary description for QuickStartDlg.
	/// </summary>
	public class QuickStartDlg : System.Windows.Forms.Form
	{
      private bool bFileOpenResult = true;
      private Settings objSettings = null;
      private System.Windows.Forms.Button btnOK;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Panel panel1;
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Button btnBrowseFolder;
      private System.Windows.Forms.RadioButton btnOpen;
      private System.Windows.Forms.RadioButton btnNew;
      private System.Windows.Forms.Button btnHelp;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.TextBox txtFolderName;
      private System.Windows.Forms.Label label4;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

      public bool FileOpenResult
      {
         get { return bFileOpenResult; }
      }

      public Settings SettingsData
      {
         get { return objSettings; }
         set { objSettings = value; }
      }

      public string FolderName
      {
         get 
         { 
            if (bFileOpenResult)
            {
               return txtFolderName.Text; 
            }
            else
            {
               return txtFolderName.Text;
            }
         }
      }

		public QuickStartDlg()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
         System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(QuickStartDlg));
         this.btnOK = new System.Windows.Forms.Button();
         this.btnHelp = new System.Windows.Forms.Button();
         this.btnOpen = new System.Windows.Forms.RadioButton();
         this.btnNew = new System.Windows.Forms.RadioButton();
         this.label2 = new System.Windows.Forms.Label();
         this.panel1 = new System.Windows.Forms.Panel();
         this.btnBrowseFolder = new System.Windows.Forms.Button();
         this.label3 = new System.Windows.Forms.Label();
         this.txtFolderName = new System.Windows.Forms.TextBox();
         this.label1 = new System.Windows.Forms.Label();
         this.label4 = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // btnOK
         // 
         this.btnOK.Location = new System.Drawing.Point(288, 312);
         this.btnOK.Name = "btnOK";
         this.btnOK.Size = new System.Drawing.Size(88, 23);
         this.btnOK.TabIndex = 9;
         this.btnOK.Text = "Continue";
         this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
         // 
         // btnHelp
         // 
         this.btnHelp.Location = new System.Drawing.Point(384, 312);
         this.btnHelp.Name = "btnHelp";
         this.btnHelp.Size = new System.Drawing.Size(88, 23);
         this.btnHelp.TabIndex = 10;
         this.btnHelp.Text = "Help";
         this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
         // 
         // btnOpen
         // 
         this.btnOpen.Checked = true;
         this.btnOpen.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.btnOpen.Location = new System.Drawing.Point(56, 72);
         this.btnOpen.Name = "btnOpen";
         this.btnOpen.Size = new System.Drawing.Size(256, 24);
         this.btnOpen.TabIndex = 3;
         this.btnOpen.TabStop = true;
         this.btnOpen.Text = "Open an Existing Category.Xml File";
         // 
         // btnNew
         // 
         this.btnNew.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.btnNew.Location = new System.Drawing.Point(56, 104);
         this.btnNew.Name = "btnNew";
         this.btnNew.Size = new System.Drawing.Size(248, 24);
         this.btnNew.TabIndex = 4;
         this.btnNew.Text = "Create a New Category.Xml File";
         // 
         // label2
         // 
         this.label2.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.label2.Location = new System.Drawing.Point(32, 152);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(424, 48);
         this.label2.TabIndex = 5;
         this.label2.Text = "In order to begin, the QuoteAdvantage Editor needs to know the name of the folder" +
            " where your CategoryList.xml file is located. This is typically going to be in t" +
            "he \\QuoteAdvantageWeb\\bin folder.";
         // 
         // panel1
         // 
         this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
         this.panel1.Location = new System.Drawing.Point(8, 296);
         this.panel1.Name = "panel1";
         this.panel1.Size = new System.Drawing.Size(464, 4);
         this.panel1.TabIndex = 9;
         // 
         // btnBrowseFolder
         // 
         this.btnBrowseFolder.Location = new System.Drawing.Point(384, 256);
         this.btnBrowseFolder.Name = "btnBrowseFolder";
         this.btnBrowseFolder.Size = new System.Drawing.Size(88, 23);
         this.btnBrowseFolder.TabIndex = 8;
         this.btnBrowseFolder.Text = "Browse...";
         this.btnBrowseFolder.Click += new System.EventHandler(this.btnBrowseFolder_Click);
         // 
         // label3
         // 
         this.label3.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.label3.Location = new System.Drawing.Point(32, 208);
         this.label3.Name = "label3";
         this.label3.Size = new System.Drawing.Size(264, 16);
         this.label3.TabIndex = 6;
         this.label3.Text = "Folder Location:";
         // 
         // txtFolderName
         // 
         this.txtFolderName.Location = new System.Drawing.Point(32, 224);
         this.txtFolderName.Name = "txtFolderName";
         this.txtFolderName.Size = new System.Drawing.Size(440, 22);
         this.txtFolderName.TabIndex = 7;
         this.txtFolderName.Text = "c:\\inetpub\\wwwroot\\QuoteAdvantageWeb\\bin";
         // 
         // label1
         // 
         this.label1.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.label1.Location = new System.Drawing.Point(32, 48);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(264, 16);
         this.label1.TabIndex = 2;
         this.label1.Text = "Please select an action:";
         // 
         // label4
         // 
         this.label4.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.label4.Location = new System.Drawing.Point(16, 16);
         this.label4.Name = "label4";
         this.label4.Size = new System.Drawing.Size(264, 16);
         this.label4.TabIndex = 1;
         this.label4.Text = "Welcome to the QuoteAdvantage Editor";
         // 
         // QuickStartDlg
         // 
         this.AcceptButton = this.btnOK;
         this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
         this.ClientSize = new System.Drawing.Size(482, 344);
         this.Controls.Add(this.label4);
         this.Controls.Add(this.label1);
         this.Controls.Add(this.btnBrowseFolder);
         this.Controls.Add(this.label3);
         this.Controls.Add(this.txtFolderName);
         this.Controls.Add(this.btnOpen);
         this.Controls.Add(this.panel1);
         this.Controls.Add(this.label2);
         this.Controls.Add(this.btnHelp);
         this.Controls.Add(this.btnOK);
         this.Controls.Add(this.btnNew);
         this.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
         this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
         this.MaximizeBox = false;
         this.MinimizeBox = false;
         this.Name = "QuickStartDlg";
         this.ShowInTaskbar = false;
         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
         this.Text = "QuoteAdvantage Editor";
         this.Load += new System.EventHandler(this.QuickStartDlg_Load);
         this.ResumeLayout(false);

      }
		#endregion
      
      private void QuickStartDlg_Load(object sender, System.EventArgs e)
      {
         txtFolderName.Text = objSettings.strMRU_CategoryList;
      }

      private void btnOK_Click(object sender, System.EventArgs e)
      {
         bool  bResult = true;

         if (btnOpen.Checked)
         {
            if (txtFolderName.Text == "")
            {
               MessageBox.Show(this, "Please the folder location of your Category.xml file", "QuoteAdvantage Editpr");
               txtFolderName.Focus();
               bResult = false;
            }
            else
            {
               if (!File.Exists(txtFolderName.Text + @"\CategoryList.xml"))
               {
                  MessageBox.Show(this, "Please enter a valid path to an existing Category.xml file", "QuoteAdvantage Editpr");
                  txtFolderName.Focus();
                  bResult = false;
               }
            }

            if (bResult)
            {
               bFileOpenResult = true;
               objSettings.strMRU_CategoryList = txtFolderName.Text;
               objSettings.SaveSettings();
            }
         }
         else
         {  
            // Don't let them do it if a file already exists
            if (File.Exists(txtFolderName.Text + @"\CategoryList.xml"))
            {
               MessageBox.Show(this, "A CategoryList.xml file already exists in this folder. Please select a different location.", "QuoteAdvantage Editor");
               txtFolderName.Focus();
               bResult = false;
            }
            else if (Directory.Exists(txtFolderName.Text) == false)
            {
               MessageBox.Show(this, "Please enter a folder location that exists.", "QuoteAdvantage Editor");
               txtFolderName.Focus();
               bResult = false;
            }


            if (bResult)
            {
               bFileOpenResult = false;
               objSettings.strMRU_CategoryList = txtFolderName.Text;
               objSettings.SaveSettings();
            }
         }

         if (bResult)
         {
            this.DialogResult = DialogResult.OK;
            this.Close();
         }
      }
        

      private void btnBrowseFolder_Click(object sender, System.EventArgs e)
      {
         DirBrowser  dlg = new DirBrowser();

         dlg.Description = "Please select a location for the new CategoryList.xml file:";
         
         if (DialogResult.OK == dlg.ShowDialog()) 
         {
            txtFolderName.Text = dlg.ReturnPath;
         }
      }

      private void btnHelp_Click(object sender, System.EventArgs e)
      {
         Process.Start("User Guide.pdf"); 
      }

	} // end class
}
